import MySQLdb

def getSecurityIDs(conn,stype=1):    
    
    sql = """SELECT security_id, short_name,trading_destination_id FROM `security` where `security_type`=%d """ % stype
    
    temp =  fetchSQL(conn, sql)
    #get the map of security_id and ticker 
    ids = dict((y, (x,z)) for x, y, z in temp) #create the ID dict -> can call ids['ACB']
    return ids

def fetchSQL(conn, sql,stype=1):
    try:                
        cursor=conn.cursor()    
        temp = cursor.execute(sql)
        res = cursor.fetchall()
    except MySQLdb.Error, e:
        print "Error %d: %s" % (e.args[0],e.args[1])
        return None    
    return res